<%@page import="java.util.List"%>
<%@page import="cn.edu.nju.ws.sview.wyge.relations.adataset.relations.Relations"%>
<%@page import="cn.edu.nju.ws.sview.wyge.relations.adataset.relations.Relation"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="cn.edu.nju.ws.sview.Config,cn.edu.nju.ws.sview.util.URIUtil,java.net.URLEncoder,java.util.Enumeration,cn.edu.nju.ws.sview.views.Entity,cn.edu.nju.ws.sview.views.View" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Relation translation</title>
<link rel="icon" href="/sview/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/sview/css/layout.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/relations/relation_translate.css" />
<link rel="stylesheet" type="text/css" href="/sview/css/easyui.css" />
<script type="text/javascript" src="/sview/script/jquery.js"></script>
<script type="text/javascript" src="/sview/script/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/sview/script/global.js"></script>
<script type="text/javascript" src="/sview/script/relations/relation_translate.js"></script>
</head>
<body>
<%
	String lang = request.getParameter("lang");
	if(lang!=null &&lang.equals("zh")){
		request.getRequestDispatcher("relation_translate_zh.jsp").forward(request,response);
		return;
	}else if(lang==null){
		lang="en" ;
	}
	String user = (String) session.getAttribute("user");
	String ds_type = request.getParameter("ds_type");
	String dsid_str =  request.getParameter("ds_id");
	String rel_str = request.getParameter("relation_id");
	String gid_str = request.getParameter("gid");
	
	int ds_id = -1;
	int relation_id = -1;
	int gid = -1;
	if(user == null || ds_type==null || dsid_str== null || rel_str == null || gid_str == null){
		String location = "../relations/index.jsp";
		if(lang.equals("zh"))
			location = location+"?lang="+lang;
		response.sendRedirect(location);
		return;
	}else{
		ds_id = Integer.parseInt(dsid_str);
		relation_id = Integer.parseInt(rel_str);
		gid = Integer.parseInt(gid_str);
	}
	Relation relation = Relation.getInstance(relation_id);
	int ov_id = relation.getOv_id();
	/*view id >0 means enter from edit point*/
	
%>
<jsp:include page="/vheader.jsp" flush="true">
   <jsp:param name="f" value="e"/>
</jsp:include>
<div class="main">
   <div class="top">
     <div class="mspacing"></div>
     <div class="operation">Relation Translate </div>
     <div class="mspacing"></div>
   </div>
   <div class="mspacingLittle"></div>
   <div class="main">
   	   <div class="mspacing"></div>
		<div class="langBox"> 
			<div class="sld">
				<span class="src-lang">Source language:</span>
				<%
					String langStr = null;
					if(lang.equals("en")){
						langStr = "English";
					}else if(lang.equals("zh")){
						langStr="中文（简体）";
					}
				%>
				<span class="srcLang"><%=langStr %></span>
			</div>
			<div class="old">
			   <span class="obj-lang">Object language:</span>
			   <span class="objLang">
			      <select id="objLang">
			       <%
			       	if(lang.equals("en")) {
			       %>
			        <option value="zh">Chinese (Simplified)</option>
			       <%	
			       	}else if(lang.equals("zh")){
			       %>
			       	 <option value="en">英语</option>
			       <% 
			       	}
			       %>
			      </select>
			   </span>
			</div>
		</div>
		<div class="mspacing"></div>
		<div class="mspacingLittle"></div>
	   <div class="mspacing"></div>
	 <div class="rcontent">
	<div class="left">
		<div class="nameBox">
			<span class="mtitle">Relation Name</span><br />
			<div class="mspacingLittle"></div>
			<%
				String relationName = relation.getName();
			%>
			<span id="rel_name" class="originTitle"><%=relationName %></span>
			<input type="text" id="relName" class="ftext"/>
		</div>
		<div class="mspacing"></div>
		<div class="mspacingLittle"></div>
		<div class="mspacing"></div>
		<div class="roleContent" >
		<span class="mtitle">Variables:</span><br />
		 <ul class="roleList" >
		 <% 
		  List<String> varibles = relation.getVariables();
		 for(String v : varibles){
		 	String role = relation.getVariableRole(v);
		 	if(role!=null && role.length()>0){
		 %>
			<div class="mspacingLittle"></div>
		 	<li class="role"><span class="originTitle" v="<%=v %>"><%=role %></span>
				<input type="text" id="<%=v %>" class="roleName ftext" value=""/>
			</li>	
		 <% }
		 } %>
		 </ul>
		</div>	
		<div class="mspacing"></div>
		 <div class="mspacingLittle"></div>
		 <div class="edit-save"> 
	     <input type="button" value="Save" class="sbutton fb">
	     <input type="button" value="Cancel" class="cbutton fb">
	     </div>	
		</div>
		
		<div class="right">
			<div id="rel_title" class="original"></div>
			<div id="rel_meta"></div>
			<div id="rel_table"></div>
		</div>
		</div>
	</div>
</div>
<input type="hidden" id="gid" value="<%=gid %>" />
<input type="hidden" id="old_id" value="<%=relation_id %>" />
<input type='hidden'  id="tr_id" value="" />
<input type='hidden'  id="ov_id" value="<%=ov_id %>" />
<input type="hidden" id="ds_type" value="<%=ds_type%>" />
<input type="hidden" id="ds_id" value="<%=ds_id%>" />
<input type="hidden" id="user" value="<%=user%>" />
<input type="hidden" id="display-lang" value="en" />
<jsp:include page="/vfooter.jsp"></jsp:include>
</body>
</html>